#define ADRENALIN_EXPORTS

#include "../include/SceneManager.h"

/// Singleton Instance
Adrenalin::SceneManager* Adrenalin::Singleton<Adrenalin::SceneManager>::_pInstance = NULL;


namespace Adrenalin
{
	SceneManager::SceneManager()
		: _currentScene(NULL)
	{
		WRITELOG(L"SceneManager Instance created", LOG_INFO);
	}

	SceneManager::~SceneManager()
	{ }

	void SceneManager::PlayScene()
	{
		if(_currentScene!=NULL)
		{
			_currentScene->Update();
		}
	}

	void SceneManager::Close()
	{
		for( std::list<Adrenalin::IScene*>::iterator i = _lstScene.begin(); 
			 i != _lstScene.end();
			 i++ )
		{
			(*i)->Close();
		}
		_lstScene.clear();
		WRITELOG(L"SceneManager Instance released", LOG_INFO);
	}

	void SceneManager::AddScene(IScene* scene)
	{
		if(SceneExists(scene->Name()))
		{
			WRITELOG(L"Scene " + scene->Name() + L" allready exists", LOG_ERROR);
		}
		else
		{
			_lstScene.push_back(scene);
			WRITELOG(L"Scene " + scene->Name() + L" added to SceneManager", LOG_INFO);

			if(_currentScene==NULL)
				_currentScene = scene;
		}
	}

	bool SceneManager::SceneExists(stringw& name)
	{
		for( std::list<Adrenalin::IScene*>::iterator i = _lstScene.begin(); 
			 i != _lstScene.end();
			 i++ )
		{
			if( (*i)->Name().compare(name) == 0)
			{
				return true;
			}
		}

		return false;
	}
};